﻿using System;
using Microsoft.EntityFrameworkCore.Migrations;
using MySql.EntityFrameworkCore.Metadata;

#nullable disable

namespace Repository.Migrations
{
    /// <inheritdoc />
    public partial class choiceNum : Migration
    {
        /// <inheritdoc />
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropForeignKey(
                name: "FK_Choice_ChoiceQuestion_ChoiceQId",
                table: "Choice");

            migrationBuilder.DropForeignKey(
                name: "FK_ChoiceAnswers_ChoiceQuestion_ChoiceQId1",
                table: "ChoiceAnswers");

            migrationBuilder.DropTable(
                name: "ChoiceQuestion");

            migrationBuilder.DropTable(
                name: "ShortAnswerQs");

            migrationBuilder.DropIndex(
                name: "IX_ChoiceAnswers_ChoiceQId1",
                table: "ChoiceAnswers");

            migrationBuilder.DropColumn(
                name: "ChoiceQId",
                table: "ChoiceAnswers");

            migrationBuilder.DropColumn(
                name: "ChoiceQId1",
                table: "ChoiceAnswers");

            migrationBuilder.RenameColumn(
                name: "ShortAnswerQId",
                table: "ShortAnswer",
                newName: "QuestionId");

            migrationBuilder.RenameColumn(
                name: "ChoiceQId",
                table: "Choice",
                newName: "QuestionId");

            migrationBuilder.RenameIndex(
                name: "IX_Choice_ChoiceQId",
                table: "Choice",
                newName: "IX_Choice_QuestionId");

            migrationBuilder.AlterColumn<Guid>(
                name: "Id",
                table: "ChoiceAnswers",
                type: "char(36)",
                nullable: false,
                oldClrType: typeof(int),
                oldType: "int")
                .OldAnnotation("MySQL:ValueGenerationStrategy", MySQLValueGenerationStrategy.IdentityColumn);

            migrationBuilder.AddColumn<Guid>(
                name: "QuestionId",
                table: "ChoiceAnswers",
                type: "char(36)",
                nullable: false,
                defaultValue: new Guid("00000000-0000-0000-0000-000000000000"));

            migrationBuilder.AddColumn<int>(
                name: "FillNumber",
                table: "Choice",
                type: "int",
                nullable: false,
                defaultValue: 0);

            migrationBuilder.CreateTable(
                name: "Questions",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "char(36)", nullable: false),
                    Type = table.Column<int>(type: "int", nullable: false),
                    Index = table.Column<int>(type: "int", nullable: false),
                    Description = table.Column<string>(type: "longtext", nullable: false),
                    SurveyId = table.Column<Guid>(type: "char(36)", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_Questions", x => x.Id);
                    table.ForeignKey(
                        name: "FK_Questions_SurveyTmplate_SurveyId",
                        column: x => x.SurveyId,
                        principalTable: "SurveyTmplate",
                        principalColumn: "Id");
                })
                .Annotation("MySQL:Charset", "utf8mb4");

            migrationBuilder.CreateIndex(
                name: "IX_Questions_SurveyId",
                table: "Questions",
                column: "SurveyId");

            migrationBuilder.AddForeignKey(
                name: "FK_Choice_Questions_QuestionId",
                table: "Choice",
                column: "QuestionId",
                principalTable: "Questions",
                principalColumn: "Id");
        }

        /// <inheritdoc />
        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropForeignKey(
                name: "FK_Choice_Questions_QuestionId",
                table: "Choice");

            migrationBuilder.DropTable(
                name: "Questions");

            migrationBuilder.DropColumn(
                name: "QuestionId",
                table: "ChoiceAnswers");

            migrationBuilder.DropColumn(
                name: "FillNumber",
                table: "Choice");

            migrationBuilder.RenameColumn(
                name: "QuestionId",
                table: "ShortAnswer",
                newName: "ShortAnswerQId");

            migrationBuilder.RenameColumn(
                name: "QuestionId",
                table: "Choice",
                newName: "ChoiceQId");

            migrationBuilder.RenameIndex(
                name: "IX_Choice_QuestionId",
                table: "Choice",
                newName: "IX_Choice_ChoiceQId");

            migrationBuilder.AlterColumn<int>(
                name: "Id",
                table: "ChoiceAnswers",
                type: "int",
                nullable: false,
                oldClrType: typeof(Guid),
                oldType: "char(36)")
                .Annotation("MySQL:ValueGenerationStrategy", MySQLValueGenerationStrategy.IdentityColumn);

            migrationBuilder.AddColumn<int>(
                name: "ChoiceQId",
                table: "ChoiceAnswers",
                type: "int",
                nullable: false,
                defaultValue: 0);

            migrationBuilder.AddColumn<Guid>(
                name: "ChoiceQId1",
                table: "ChoiceAnswers",
                type: "char(36)",
                nullable: true);

            migrationBuilder.CreateTable(
                name: "ChoiceQuestion",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "char(36)", nullable: false),
                    SurveyId = table.Column<Guid>(type: "char(36)", nullable: true),
                    Description = table.Column<string>(type: "longtext", nullable: false),
                    Index = table.Column<int>(type: "int", nullable: false),
                    IsMutipleChoice = table.Column<bool>(type: "tinyint(1)", nullable: false),
                    Type = table.Column<int>(type: "int", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_ChoiceQuestion", x => x.Id);
                    table.ForeignKey(
                        name: "FK_ChoiceQuestion_SurveyTmplate_SurveyId",
                        column: x => x.SurveyId,
                        principalTable: "SurveyTmplate",
                        principalColumn: "Id");
                })
                .Annotation("MySQL:Charset", "utf8mb4");

            migrationBuilder.CreateTable(
                name: "ShortAnswerQs",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "char(36)", nullable: false),
                    SurveyId = table.Column<Guid>(type: "char(36)", nullable: true),
                    Description = table.Column<string>(type: "longtext", nullable: false),
                    Index = table.Column<int>(type: "int", nullable: false),
                    Type = table.Column<int>(type: "int", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_ShortAnswerQs", x => x.Id);
                    table.ForeignKey(
                        name: "FK_ShortAnswerQs_SurveyTmplate_SurveyId",
                        column: x => x.SurveyId,
                        principalTable: "SurveyTmplate",
                        principalColumn: "Id");
                })
                .Annotation("MySQL:Charset", "utf8mb4");

            migrationBuilder.CreateIndex(
                name: "IX_ChoiceAnswers_ChoiceQId1",
                table: "ChoiceAnswers",
                column: "ChoiceQId1");

            migrationBuilder.CreateIndex(
                name: "IX_ChoiceQuestion_SurveyId",
                table: "ChoiceQuestion",
                column: "SurveyId");

            migrationBuilder.CreateIndex(
                name: "IX_ShortAnswerQs_SurveyId",
                table: "ShortAnswerQs",
                column: "SurveyId");

            migrationBuilder.AddForeignKey(
                name: "FK_Choice_ChoiceQuestion_ChoiceQId",
                table: "Choice",
                column: "ChoiceQId",
                principalTable: "ChoiceQuestion",
                principalColumn: "Id");

            migrationBuilder.AddForeignKey(
                name: "FK_ChoiceAnswers_ChoiceQuestion_ChoiceQId1",
                table: "ChoiceAnswers",
                column: "ChoiceQId1",
                principalTable: "ChoiceQuestion",
                principalColumn: "Id");
        }
    }
}
